#include "random.h"

#include <stdlib.h>

// http://www.concentric.net/~Ttwang/tech/inthash.htm
// designed for 32-bit ints
unsigned int pcg_hash(unsigned int a) {
	a = (a+0x7ed55d16) + (a<<12);
	a = (a^0xc761c23c) ^ (a>>19);
	a = (a+0x165667b1) + (a<<5);
	a = (a+0xd3a2646c) ^ (a<<9);
	a = (a+0xfd7046c5) + (a<<3);
	a = (a^0xb55a4f09) ^ (a>>16);
	return a;
}

unsigned int pcg_hash2(unsigned int x, unsigned int y) {
	return pcg_hash(x ^ pcg_hash(y));
}

unsigned int pcg_hash3(unsigned int x, unsigned int y, unsigned int z) {
	return pcg_hash(x ^ pcg_hash(y ^ pcg_hash(z)));
}

void pcg_sdrand(unsigned long seed) {
	srand48(seed);
}

double pcg_drand() {
	return drand48();
}
